
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel=stylesheet href='include/hoj.css' type='text/css'>
</head>
<body>
<center>
<div style="width:90%; text-align:left">
<img src="image/logo.png"/>
</div>
<table width=96%> 
	<tr align="center" class='hd' valign="top">
				<th><a href="faqs.php">F.A.Qs</a></th>
		<th><a href="./bbs.php">Web Board</a></th>
		<th><a href="./">Home</a></th>
		<th><a href="./problemset.html">ProblemSet</a></th>
		<th><a href="./status.php">Status</a></th>
		<th><a href="./ranklist.php">Ranklist</a></th>
		<th><a href="./contest.php">Contest</a></th>
		<th><a href=loginpage.php>Login</a></th><th><a href=registerpage.php>Register</a></th>	</tr>
</table>
</center>
<center>
<div class="notice">
	<div>
		<B>Notice:</B>鉴于种种原因，本OJ自下周星期一（3月5号）开始不再全面开放，请各位做好善后事宜，谢谢合作。	</div>
</div>
</center>
</div>
<title>Problem 2203. -- Pku2448 A New Operating System
</title><center><h2>2203: Pku2448 A New Operating System
</h2><span class=green>Time Limit: </span>10 Sec&nbsp;&nbsp;<span class=green>Memory Limit: </span>259 MB<br><span class=green>Submit: </span>24&nbsp;&nbsp;<span class=green>Solved: </span>8<br>[<a href='submitpage.php?id=2203'>Submit</a>][<a href='problemstatus.php?id=2203'>Status</a>][<a href='bbs.php?id=2203'>Discuss</a>]</center><h2>Description</h2><div class=content>May is a lovely girl. Due to her filial piety, she wants to give a present on her mother's birthday. Because both her parents are the top programmer in the world, she decided to design a new program, a special program that is an Operating System! With the help of her excellent programming skill, May has already finished the kernel of the new OS. And the birthday is coming, she is afraid that time is not enough to finish the entire project in time. As her best net-pal, it's your duty to help her. 
This is a multitask OS, processes run at the same time. There are following command in the OS: 

CreateProcess(PID,Memory,Priority) 
A new process is created with the process identification PID and memory size, and a priority. The priority in this command is called outer priority of a process. 

AddMessage(PID,Priority) 
That means, add a new message to the message queue of process PID, with the priority of Priority. The message with higher Priority will run earlier that lower ones. The Priority is called inner priority. 

Run 
Find out the message with biggest HP. HP is defined as the product of the inner priority of a message and the corresponding process priority. If two or more messages have the same HP, the one with smallest PID will run first. Print the information "Run: HP" to the output file, HP will be replaced by the message HP you found, or print "Empty" instead if the message queue is empty. Finally remove this message if exist. 

ChangePriority(PID,NewValue) 
Change the outer priority of process PID to NewValue. 

GetMemory(PID,Memory) 
Process PID memory increases the amount of Memory. 

FreeMemory(PID,Memory) 
Process PID memory decreases the amount of Memory. 

RunProcess(PID) 
Similar with Run command. Find out the message in the process PID message queue, print the information "Run Process: Priority" to the output file, Priority will be replaced by the message priority you found, or print "Empty" instead if the message queue is empty. Finally remove this message if exist. 

CloseMaxMemory 
Find out the process that used the largest number of memory and close it if exists (if tie, the one with smallest PID should be release first), or print "Empty" instead. 

CloseProcess(PID) 
Close the process with the identification of PID. 

Whenever a process' memory is less than or equal to 0, it will be close automatically. In any of the above commands except the first one, if the PID doesn't exist, please print an "Error" to the output. For the first command, if the PID is already exist, print an "Error" and ignore this command. 
Input
First line in the input is an integer number N (1 <= N <= 100000), which represents the number of commands. The next N lines, each gives a command described above. Any number given in the input file will be non-negative integer and will not be more than 1000000000. 
Output
The output format has been described above.
Sample Input
11
CloseMaxMemory
CreateProcess(1,100,1)
CreateProcess(2,200,1)
CreateProcess(3,300,1)
AddMessage(1,9)
AddMessage(2,19)
AddMessage(1,10)
GetMemory(2,999)
CloseMaxMemory
Run
RunProcess(1)
Sample Output
Empty
Run: 10
Run Process: 9






中文翻译：(最好自己见English Version )


请你编一个程序，实现下述功能：
1.	CreateProcess(PID,Memory,Priority)
创造一个新的进程( 编号,占用内存,优先级 )
在这个命令中的优先级称做Outer Priority

2.	AddMessage(PID,Priority) 
将一条优先级为Priority的message插入编号为Pid的进程的message队列中。有着更高priority的message将会被运行的更早。这里的priority称做 inner priority。

3.	Run
找出具有最大HP的message( Hp= inner priority * outer priority ),如果有多个，取所在进程编号最小的一个。
输出 “Run: HP”，并删除此message。如果不存在这样的message,输出’Empty’。


4.	ChangePriority(PID,NewValue)
将编号为PID的进程的inner priority改为Newvalue

5.	GetMemory(PID,Memory)
将编号为PID的进程的memory+=Newvalue 

6.	FreeMemory(PID,Memory)
将编号为PID的进程的memory-=Newvalue

7.	RunProcess(PID) 
与Run命令相似,不过message要求在编号为PID的进程的message队列中,
输出 “Run Process: Priority”,(  Priority 为message 的优先级 ), 并删除此message,如果不存在这样的message,输出’Empty’

8.	CloseMaxMemory 
将Memory最大的进程关闭（ 如有多个,取编号最小 ）
如果不存在,输出”Empty” 

9.	CloseProcess(PID) 
将编号为PID的进程关闭

     无论何时，如果一个进程的Memory <=0,它将会自动关闭。在上述操作（Except first one ）中，如果PID不存在，输出”Error”,对于第一个操作，如果PID已存在，则输出”Error”,并忽略此操作。


</div><h2>Input</h2><div class=content>第一行,一个整数N( 1<=N<=100000),操作总数。
下面N行，每行将会给出上述的操作之一。
在Input中出现的数字都是非负的，且不超过1000000000
</div><h2>Output</h2><div class=content></div><h2>Sample Input</h2>
			<div class=content><span class=sampledata>11<br />
CloseMaxMemory<br />
CreateProcess(1,100,1)<br />
CreateProcess(2,200,1)<br />
CreateProcess(3,300,1)<br />
AddMessage(1,9)<br />
AddMessage(2,19)<br />
AddMessage(1,10)<br />
GetMemory(2,999)<br />
CloseMaxMemory<br />
Run<br />
RunProcess(1)<br />
<br />
</span></div><h2>Sample Output</h2>
			<div class=content><span class=sampledata>Empty<br />
Run: 10<br />
Run Process: 9<br />
<br />
</span></div><h2>HINT</h2>
			<div class=content><p></p></div><h2>Source</h2>
			<div class=content><p><a href='problemset.html?search=模拟题系列'>模拟题系列</a></p></div><center>[<a href='submitpage.php?id=2203'>Submit</a>][<a href='problemstatus.php?id=2203'>Status</a>][<a href='bbs.php?id=2203'>Discuss</a>]</center>﻿<br>

<a href="./"><span class=red>HOME</span></a>
<a href="javascript:history.go(-1)"><span class=red>Back</span></a>

<hr>
<center>
	<div class="footer">
			<a href=setlang.php?lang=ko>한국어</a>&nbsp;
		<a href=setlang.php?lang=cn>中文</a>&nbsp;
		<a href=setlang.php?lang=fa>فارسی</a>&nbsp;
		<a href=setlang.php?lang=en>English</a>&nbsp;
		<a href=setlang.php?lang=th>ไทย</a>
	<br>		<div>版权所有 &copy;2008-2012 WaterPark Organization. | <script src="http://s21.cnzz.com/stat.php?id=2982771&web_id=2982771" language="JavaScript"></script>
</div>
		<div>Based on opensource project <a href="http://hustoj.googlecode.com">hustoj</a>.</div>
	</div>
</center>
</body>
</html>
